<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Put snapshot lifecycle policy API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'slm-api-put-policy.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/slm-api-put-policy.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/slm-api-put-policy.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/slm-api-put-policy.html" rel="nofollow" target="_blank">../en/slm-api-put-policy.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="snapshot-lifecycle-management-api.html">Snapshot lifecycle management API</a></span>
»
<span class="breadcrumb-node">Put snapshot lifecycle policy API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="snapshot-lifecycle-management-api.html">« Snapshot lifecycle management API</a>
</span>
<span class="next">
<a href="slm-api-get-policy.html">Get snapshot lifecycle policy API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="slm-api-put-policy"></a>Put snapshot lifecycle policy API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Creates or updates a snapshot lifecycle policy.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">PUT /_slm/policy/&lt;snapshot-lifecycle-policy-id&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-prereqs"></a>Prerequisites<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<p>If the Elasticsearch security features are enabled, you must have the
<code class="literal">manage_slm</code> cluster privilege and the <code class="literal">manage</code> index privilege
for any included indices to use this API.
For more information, see <a class="xref" href="security-privileges.html" title="Security privileges">Security privileges</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Use the put snapshot lifecycle policy API
to create or update a snapshot lifecycle policy.</p>
<p>If the policy already exists,
this request increments the policy’s version.
Only the latest version of a policy is stored.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;snapshot-lifecycle-policy-id&gt;</code>
</span>
</dt>
<dd>
(Required, string)
ID for the snapshot lifecycle policy
you want to create or update.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
</dl>
</div>
</div>

<div class="section child_attributes">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">config</code>
</span>
</dt>
<dd>
<p>
(Required, object)
Configuration for each snapshot created by the policy.
</p>
<details open>
<summary class="title">Properties of <code class="literal">config</code></summary>
<div class="content">
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">ignore_unavailable</code>
</span>
</dt>
<dd>
(Optional, boolean)
If <code class="literal">true</code>, missing indices do <span class="strong strong"><strong>not</strong></span> cause snapshot creation to fail and return
an error. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">include_global_state</code>
</span>
</dt>
<dd>
(Optional, boolean)
If <code class="literal">true</code>, cluster states are included in snapshots. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">indices</code>
</span>
</dt>
<dd>
(Optional, array of strings)
Array of index names or wildcard pattern of index names included in snapshots. It
supports <a class="xref" href="date-math-index-names.html" title="Date math support in index names">date math</a> expressions.
</dd>
</dl>
</div>
</div>
</details>
</dd>
<dt>
<span class="term">
<code class="literal">name</code>
</span>
</dt>
<dd>
(Required, string)
Name automatically assigned to each snapshot created by the policy. This value
supports the same <a class="xref" href="date-math-index-names.html" title="Date math support in index names">date math</a> supported in index names.
To prevent conflicting snapshot names, a UUID is automatically appended to each
snapshot name.
</dd>
<dt>
<span class="term">
<code class="literal">repository</code>
</span>
</dt>
<dd>
(Required, string)
Repository used to store snapshots created by this policy. This repository must
exist prior to the policy’s creation. You can create a repository using the
<a class="xref" href="modules-snapshots.html" title="Snapshot module">snapshot repository API</a>.
</dd>
</dl>
</div>
<div class="variablelist">
<a id="slm-api-put-retention"></a>
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">retention</code>
</span>
</dt>
<dd>
<p>
(Optional, object)
Retention rules used to retain and delete snapshots created by the policy.
</p>
<details open>
<summary class="title">Properties of <code class="literal">retention</code></summary>
<div class="content">
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">expire_after</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>)
Time period after which a snapshot is considered expired and eligible for
deletion.
</dd>
<dt>
<span class="term">
<code class="literal">max_count</code>
</span>
</dt>
<dd>
(Optional, integer)
Maximum number of snapshots to retain, even if the snapshots have not yet
expired. If the number of snapshots in the repository exceeds this limit, the
policy retains the most recent snapshots and deletes older snapshots.
</dd>
<dt>
<span class="term">
<code class="literal">min_count</code>
</span>
</dt>
<dd>
(Optional, integer)
Minimum number of snapshots to retain, even if the snapshots have expired.
</dd>
</dl>
</div>
</div>
</details>
</dd>
<dt>
<span class="term">
<code class="literal">schedule</code>
</span>
</dt>
<dd>
(Required, <a class="xref" href="cron-expressions.html" title="Cron expressions">Cron syntax</a>)
Periodic or absolute schedule at which the policy creates snapshots and deletes
expired snapshots. Schedule changes to existing policies are applied immediately.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="slm-api-put-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/slm/apis/slm-put.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Create a <code class="literal">daily-snapshots</code> lifecycle policy:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /_slm/policy/daily-snapshots
{
  "schedule": "0 30 1 * * ?", <a id="CO662-1"></a><i class="conum" data-value="1"></i>
  "name": "&lt;daily-snap-{now/d}&gt;", <a id="CO662-2"></a><i class="conum" data-value="2"></i>
  "repository": "my_repository", <a id="CO662-3"></a><i class="conum" data-value="3"></i>
  "config": { <a id="CO662-4"></a><i class="conum" data-value="4"></i>
    "indices": ["data-*", "important"], <a id="CO662-5"></a><i class="conum" data-value="5"></i>
    "ignore_unavailable": false,
    "include_global_state": false
  },
  "retention": { <a id="CO662-6"></a><i class="conum" data-value="6"></i>
    "expire_after": "30d", <a id="CO662-7"></a><i class="conum" data-value="7"></i>
    "min_count": 5, <a id="CO662-8"></a><i class="conum" data-value="8"></i>
    "max_count": 50 <a id="CO662-9"></a><i class="conum" data-value="9"></i>
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2142.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>When the snapshot should be taken, in this case, 1:30am daily</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The name each snapshot should be given</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>Which repository to take the snapshot in</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>Any extra snapshot configuration</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-5"><i class="conum" data-value="5"></i></a></p>
</td>
<td align="left" valign="top">
<p>Which indices the snapshot should contain</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-6"><i class="conum" data-value="6"></i></a></p>
</td>
<td align="left" valign="top">
<p>Optional retention configuration</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-7"><i class="conum" data-value="7"></i></a></p>
</td>
<td align="left" valign="top">
<p>Keep snapshots for 30 days</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-8"><i class="conum" data-value="8"></i></a></p>
</td>
<td align="left" valign="top">
<p>Always keep at least 5 successful snapshots, even if they’re more than 30 days old</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO662-9"><i class="conum" data-value="9"></i></a></p>
</td>
<td align="left" valign="top">
<p>Keep no more than 50 successful snapshots, even if they’re less than 30 days old</p>
</td>
</tr>
</table>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="snapshot-lifecycle-management-api.html">« Snapshot lifecycle management API</a>
</span>
<span class="next">
<a href="slm-api-get-policy.html">Get snapshot lifecycle policy API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>